/*
 * Copyright 2012 Marsrutai.lt
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package lt.marsrutai.mobile.android.model;

import java.util.Calendar;

import lt.marsrutai.mobile.android.model.enums.DateTime;
import lt.marsrutai.mobile.android.model.enums.VehicleDirection;
import lt.marsrutai.mobile.android.util.ParcelUtil;
import android.os.Parcel;
import android.os.Parcelable;

public class VehiclePosition implements Parcelable {
    
    public static final Parcelable.Creator<VehiclePosition> CREATOR = new Parcelable.Creator<VehiclePosition>() {

        @Override
        public VehiclePosition createFromParcel(Parcel in) {
            return new VehiclePosition(in);
        }

        @Override
        public VehiclePosition[] newArray(int size) {
            return new VehiclePosition[size];
        }
    };

    private VehicleDirection direction;
    private Double directionAngle;
    private String directionName;
    
    private Double latitude;
    private Double longitude;
    
    private Calendar positionTime;
    private String scheduleName;
    private String transportId;
    private String scopeFolder;

    public VehiclePosition() {
    }

    public VehiclePosition(Parcel in) {
        direction = VehicleDirection.parseEnum(in.readString());
        directionAngle = ParcelUtil.readDouble(in);
        directionName = in.readString();

        longitude = ParcelUtil.readDouble(in);
        latitude = ParcelUtil.readDouble(in);

        if (in.readInt() == 1) {
            positionTime = new DateTime(in.readLong()).getCalendar();
        }
        
        scheduleName = in.readString();
        transportId = in.readString();
        scopeFolder = in.readString();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(direction.toString());
        ParcelUtil.writeDouble(dest, directionAngle);
        dest.writeString(directionName);

        ParcelUtil.writeDouble(dest, longitude);
        ParcelUtil.writeDouble(dest, latitude);
        
        if (positionTime == null) {
            dest.writeInt(0);
        }
        else {
            dest.writeInt(1);
            dest.writeLong(positionTime.getTimeInMillis());
        }

        dest.writeString(scheduleName);
        dest.writeString(transportId);
        dest.writeString(scopeFolder);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public VehicleDirection getDirection() {
        return direction;
    }

    public void setDirection(VehicleDirection direction) {
        this.direction = direction;
    }

    public Double getDirectionAngle() {
        return directionAngle;
    }

    public void setDirectionAngle(Double directionAngle) {
        this.directionAngle = directionAngle;
    }

    public String getDirectionName() {
        return directionName;
    }

    public void setDirectionName(String directionName) {
        this.directionName = directionName;
    }

    public Double getLatitude() {
        return latitude;
    }

    public void setLatitude(Double latitude) {
        this.latitude = latitude;
    }

    public Double getLongitude() {
        return longitude;
    }

    public void setLongitude(Double longitude) {
        this.longitude = longitude;
    }

    public Calendar getPositionTime() {
        return positionTime;
    }

    public void setPositionTime(Calendar positionTime) {
        this.positionTime = positionTime;
    }

    public String getScheduleName() {
        return scheduleName;
    }

    public void setScheduleName(String scheduleName) {
        this.scheduleName = scheduleName;
    }

    public String getTransportId() {
        return transportId;
    }

    public void setTransportId(String transportId) {
        this.transportId = transportId;
    }

    public String getScopeFolder() {
        return scopeFolder;
    }

    public void setScopeFolder(String scopeFolder) {
        this.scopeFolder = scopeFolder;
    }

}
